//
//  UserViewController.m
//  掌上海印
//
//  Created by admin on 16/4/13.
//  Copyright © 2016年 handsome. All rights reserved.
//

#import "UserViewController.h"
#import "myTableViewCell.h"
#import "otherCell.h"
#import "IndexRow.h"
#import "IndexSection.h"
#import "QRcedeView.h"
#import "UserFeedBackViewController.h"
#import "WorkViewController.h"
#import "AboutUs.h"
#import "WebViewController.h"
#import "Setting.h"
#import "RulesViewController.h"
#import "UserSetting.h"


@interface UserViewController()
@property (nonatomic, strong) NSArray *listArray;

@end

@implementation UserViewController
- (NSArray *)listArray{
    if (!_listArray) {
        NSString * path = [[NSBundle mainBundle] pathForResource:@"cell.plist" ofType:nil];
        NSArray * dicArr = [NSArray arrayWithContentsOfFile:path];
        
        NSMutableArray * arr = [NSMutableArray array];
        for (NSDictionary *dict in dicArr) {
            IndexSection *section = [IndexSection parsingJsonWithDictionary:dict];
            [arr addObject:section];
        }
        _listArray = arr;
    }
    return _listArray;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.leftBarButtonItem = nil;
    self.view.backgroundColor = bgColor;
    self.title = @"我";
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 0.1;
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    self.tabBarController.tabBar.hidden = NO;
}

-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (section == 0) {
        return 1;
    }else if (section ==1)
    {
        return 2;
    }else if (section ==2)
    {
        return 3;
    }
    else
    {
        return 1;
    }
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 4;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section == 0) {
        myTableViewCell *newcell = [myTableViewCell myTableViewCellWithTableView:tableView];
        newcell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
        return newcell;
    }
    else
    {
        otherCell *cell = [otherCell otherCellWithTableView:tableView];
        cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
        IndexSection *section = self.listArray[indexPath.section-1];
        IndexRow *row = section.rows [indexPath.row];
        cell.inderow = row;
        return cell;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    if (section ==0) {
        return 10;
    }
    else{
        
        return 20;
    }
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section ==0) {
        return 70;
    }else{
        return 45;
    }
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.section ==0) {
    
        [self.navigationController pushViewController:[[UserSetting alloc]init] animated:YES]; //跳转到下一页面
    }
    else if (indexPath.section ==1)
    {
        if (indexPath.row == 0) {
            
            [self.navigationController pushViewController:[[WorkViewController alloc]init] animated:YES];
        }else
        {
            [self.navigationController pushViewController:[[RulesViewController alloc]init] animated:YES];
        }
    }
    else if (indexPath.section ==2)
    {
        if (indexPath.row== 0) {
            [self.navigationController pushViewController:[[WebViewController alloc]init] animated:YES];
        }
        else if (indexPath.row ==1)
        {
            [self.navigationController pushViewController:[[AboutUs alloc]init] animated:YES];
        }
        else
        {
            [self.navigationController pushViewController:[[UserFeedBackViewController alloc]init] animated:YES];
        }
    }
    else
    {
        [self.navigationController pushViewController:[[Setting alloc]init] animated:YES];
    }
    
}
@end
